<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
 	<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0,         maximum-scale=1.0, user-scalable=no,minimal-ui" />
    <title>找回密码</title>
    <link rel="stylesheet" href="__PUBLIC__/Mobile/css/base.css">
    <link rel="stylesheet" href="__PUBLIC__/Mobile/css/find_password.css"/>
    <script src="__PUBLIC__/Mobile/js/jquery-1.7.2.min.js"></script>
    <script src="__PUBLIC__/Mobile/layer/layer.min.js"></script>
</head>

<body>
	<div class="title">
    	<div class="back_btn">
            <a href="javascript:history.back(-1);"> <img src="__PUBLIC__/Mobile/images/arrow.png" style="width:20%;"></a>
        </div>
        <p>找回密码</p>
    </div>
    <div class="discrible">
    	<p>点击获取验证码。系统会给您账号所绑定或注册的手机号
<span><?php  echo substr_replace($data['phone'],'******',3,6);  ?></span>发送一条验证短信</p>
    </div>
    <div class="dl clearfix">
    	<div class="user clearfix">
        	<div class="user_icon">
            	<img src="__PUBLIC__/Mobile/images/yx.png">
            </div>
            <div class="u_right">
            	<div class="u_right_content clearfix">
            		<input type="hidden" name="phones" value = "{$data['phone']}">
                    <input type="text" placeholder="请输入短信验证码" name="code">
                    <div class="yz" id="yzm">
                        <p>获取验证码</p>
                    </div>
              	</div>
            </div>
        </div>
        <div class="password clearfix">
        	<div class="password_icon">
            	<img src="__PUBLIC__/Mobile/images/password.png">
            </div>
            <div class="p_right">
            	<div class="p_right_content clearfix">
                    <input type="password" placeholder="请设置新密码(字母和数字组合的6-16个字符)" name="password">
              	</div>
            </div>
        </div>
    </div>
    <div class="dl_btn">
    	<div class="dl_btn_son" id="button">重置密码</div>
    </div>
    
    <script>
		var $verify;
		$("#yzm").click(function(){
			var validCode=true;
			var time=60;
			var codes=$(this);
			var phone = $("input[name=phones]").val();
			$.ajax({
   			 url: "{:U('User/findpass_code')}",
                type: "POST",
                data: {phone:phone},
                dataType: "json",
                success: function(result){
                      if(result.isok=='ok'){
                    	  if (validCode) {
  		        			validCode=false;
  		        			codes.addClass("msgs1");
  		        			var t=setInterval(function  () {
  		        			time--;
  		        			codes.html("等待"+time+"秒");
  		        			if (time==0) {
  		        				clearInterval(t);
  		        			codes.html("重新获取");
  		        				validCode=true;
  		        			codes.removeClass("msgs1");
  		        				}
  		        			},1000)
  		        		}
                   	     layer.alert('验证码为已发送成功',6);
                   		 $verify = result.code;
                      }else{
                   	     layer.msg('验证码未获取到',2);
                      }    
                }
            });
		});
		
		$("#button").click(function(){
    		var phone = $("input[name=phones]").val();
    		var code = $("input[name=code]").val();
    		var password = $("input[name=password]").val();
    		if(!code){
    			layer.msg('验证码不能为空',2);
    			return false;
    		}
    		if(code != $verify ){
    			layer.msg('验证码不正确',2);
    			return false;
    		}
    		if(!password){
    			layer.msg('新密码不能为空',2);
    			return false;
    		}

    		
    		$.ajax({
   			 url: "{:U('User/find_password')}",
                type: "POST",
                data: {phone:phone,password:password},
                dataType: "json",
                success: function(result){
                	if(result.isok=='ok'){
                 	   layer.alert('恭喜你,新密码创建成功,快登录吧',1);
                 	   location.href = "{:U('User/login')}";
                    }else if(result.isok=='off'){
                 	   layer.msg('修改失败',2);
                    }
                }
            });
    		
    	});
	</script>
    
</body>
</html>